//
//  Client.h
//  BetsAndBrains
//
//  Created by Augustine, Eric M (augus011) on 4/28/12.
//  Copyright 2012 __MyCompanyName__. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "AsyncUdpSocket.h"
#import "Game.h"
#import "LobbyViewController.h"


@class ClientMessageListener;

/*
 
 Adam Nelson - 4/28/2012
 -----------------------
 
 This class uses AsyncUdpSocket for making a UDP connetion.
 The documentation about it can be found here:
 http://homepages.ius.edu/rwisman/C490/html/AsyncSocket%20Documentation.html
 
 It is public domain. As far as I can tell it uses native Obj-C connection methods
 but makes it easier to use. 
 
 The source here is subject to change but I am pretty sure I found all of the equivalent
 data types required in the Java/Android version of the game. 
 
 */

@interface Client : NSObject {
	bool* VERBOSE;
	AsyncUdpSocket* clientSocket;
	NSString* serverSocketAddress;
	UInt16* serverSocketPort;
	NSInteger* clientKey;
	NSString* clientName;
	bool connected;
	ClientMessageListener* listener;
	Game* game;
	NSDictionary* packetResponses;
	LobbyViewController* lobby;
	NSArray* errorQueue;
	bool* running;
}

@property bool* VERBOSE;
@property (retain) AsyncUdpSocket* clientSocket;
@property (retain) NSString* serverSocketAddress;
@property UInt16* serverSocketPort;
@property NSInteger* clientKey;
@property (retain) NSString* clientName;
@property bool connected;
@property (retain) ClientMessageListener* listener;
@property (retain) Game* game;
@property (retain) NSDictionary* packetResponses;
@property (retain) LobbyViewController* lobby;
@property (retain) NSArray* errorQueue;
@property  bool* running;

/*
 
 Adam Nelson - 4/28/2012
 -----------------------
 
 The CFDataRef packets may change depending on how the
 AsyncSocket reads in packets. It is also dependent on
 whether we end up using it or not.
 
 */

-(void) init;
-(void) run;
-(void) setListener: (ClientMessageListener*)listener;
-(bool) sendPacketWaitForResponse: (CFDataRef*)packet;
-(void) handleConnectionResponse: (CFDataRef*)packet;
-(void) sendConnectionRequest;
-(void) sendJoinGameRequest: (NSInteger)gameID;
-(void) sendServerLobbyInfoRequest;
-(void) handleServerLobbyInfoResponse: (CFDataRef*)packet;
-(void) handleGameLobbyInfo: (CFDataRef*)packet;
-(void) sendCreateGameRequest: (NSString*) gameName :(NSInteger*) rounds :(NSArray*) categories;
-(void) sendStartGameRequest: (NSInteger*) gameID;
-(void) handleQuestion: (CFDataRef*)packet;
-(void) sendAnswer:(NSInteger*) gameID :(NSInteger*) answer;
-(void) handleRoundResults: (CFDataRef*)packet;
-(void) sendNextRoundRequest: (NSInteger*) gameID;
-(void) sendLeaveGameRequest: (NSInteger*) gameID;
-(void) handleGameResults: (CFDataRef*)packet;
-(void) sendDisconnect;
-(void) handBettingOdds: (CFDataRef*)packet;
-(void) sendSubmitBets: (NSArray*) bets :(NSInteger*) gameID;
-(void) sendAreYouStillThere;
-(void) sendJoinGameInviteEmail: (NSString*) to :(NSString*) from :(NSString*) content;
-(void) handleAreYouStillThere: (CFDataRef*)packet;
-(void) sendMessageReceived: (Byte*) messageType;
-(void) handleMessageReceived: (CFDataRef*)packet;
-(LobbyViewController*) getLobby;
-(void) handleError: (CFDataRef*)packet;
-(bool) isErrorQueueEmpty;
-(NSString*) getError;
-(void) endClientThread;

@end
